package springboot.service;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;
import springboot.bean.*;
import springboot.http.HttpClientTools;
import springboot.kernel.KernelTools;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
public class StackService {
    KernelTools km = new KernelTools();
    String v1OrderName=null;
    String v2OrderName=null;
    String v3OrderName=null;
    String v4OrderName=null;
    String v5OrderName=null;
    String v6OrderName=null;
    String v7OrderName=null;
    String v8OrderName=null;
    MoveFinish_Request moveFinish_request=null;
    Data data=null;
    DataMove dataMove=null;
    GetFinish_Request getFinish_request=null;
    List<Data> list=null;
    int A1=0;int A2=0;int A3=0;int A4=0;int A5=0;int A6=0;int A7=0;int A8=0;
    int B1=0;int B2=0;int B3=0;int B4=0;int B5=0;int B6=0;int B7=0;int B8=0;
    int C1=0;int C2=0;int C3=0;int C4=0;int C5=0;int C6=0;int C7=0;int C8=0;
    int D1=0;int D2=0;int D3=0;int D4=0;int D5=0;int D6=0;int D7=0;int D8=0;

    public class changeState implements Runnable{
        @Override
        public void run() {
            while(true) {
                try {
                    Thread.sleep(700);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (D1==0){
                    v1OrderName=km.getTranspotOrder("Vehicle-0001");
                    A1=0;B1=0;C1=0;
                }
                if (D2==0){
                    v2OrderName=km.getTranspotOrder("Vehicle-0002");
                    A2=0;B2=0;C2=0;
                }
                if (D3==0){
                    v3OrderName=km.getTranspotOrder("Vehicle-0003");
                    A3=0;B3=0;C3=0;
                }
                if (D4==0){
                    v4OrderName=km.getTranspotOrder("Vehicle-0004");
                    A4=0;B4=0;C4=0;
                }
                if (D5==0){
                    v5OrderName=km.getTranspotOrder("Vehicle-0005");
                    A5=0;B5=0;C5=0;
                }
                if (D6==0){
                    v6OrderName=km.getTranspotOrder("Vehicle-0006");
                    A6=0;B6=0;C6=0;
                }
                if (D7==0){
                    v7OrderName=km.getTranspotOrder("Vehicle-0007");
                    A7=0;B7=0;C7=0;
                }
                if (D8==0){
                    v8OrderName=km.getTranspotOrder("Vehicle-0008");
                    A8=0;B8=0;C8=0;
                }
                /*使用ifelse有一个弊端，任务结束条件不满足进不去*/
                if(!v1OrderName.equals("N/A")) {
                        if(!v1OrderName.startsWith("Park") && !v1OrderName.startsWith("Recharge")
                                && !v1OrderName.startsWith("TOrder") && !v1OrderName.startsWith("Move")) {
                                if (D1==0){
                                    D1=1;
                                }
                                //获得地堆放货地点属性
                                String end=km.getPropertyByOrder(v1OrderName,"end");
                                String UUID=km.getPropertyByOrder(v1OrderName,"UUID");
                                String Lpnnumber=km.getPropertyByOrder(v1OrderName,"Lpnnumber");
                            if(A1==0&&km.getDriveOrderOperation(v1OrderName).startsWith("Unload")&&
                               km.getDriveOrderState(v1OrderName).equals("TRAVELLING")&&
                               //并且当前点位不等于放货进叉点位
                               !km.getPosition("Vehicle-0001").equals(km.getDriverOrderPoint(v1OrderName))
                               ){
                               getFinish_request=new GetFinish_Request();
                               getFinish_request.setuUID(UUID);
                               getFinish_request.setRequestAPI("Ord_GetFinish");
                               list=new ArrayList<Data>();
                               data=new Data();
                               data.setOrderId(v1OrderName);
                               data.setRgnNO("01");
                               list.add(data);
                               getFinish_request.setList(list);
                               String jsonOutput= JSON.toJSONString(getFinish_request);
                               try {
                                   String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_GetFinish",jsonOutput,"utf-8");
                                   Response response=JSON.parseObject(jsonReturn, Response.class);
                                   System.out.println("一车取货完成");
                                   System.out.println("反馈的内容是"+response.getCode());
                               } catch (IOException e) {
                                   e.printStackTrace();
                               }
                               A1=1;
                            }
                            String v1orderStatus = km.getOrderStatus(v1OrderName);
                            if(B1==0&&v1orderStatus.equals("FINISHED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(1);
                                dataMove.setLpnnumber(Lpnnumber);
                                dataMove.setOrderId(v1OrderName);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("一车放货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                B1=1;
                                D1=0;
                            }
                            if(C1==0&&v1orderStatus.equals("FAILED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(2);
                                dataMove.setOrderId(v1OrderName);
                                dataMove.setLpnnumber(Lpnnumber);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("一车任务失败");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                C1=1;
                                D1=0;
                            }
                        }
                }
                /*上一个更新*/
                if(!v2OrderName.equals("N/A")) {
                    if(!v2OrderName.startsWith("Park") && !v2OrderName.startsWith("Recharge")
                            && !v2OrderName.startsWith("TOrder") && !v2OrderName.startsWith("Move")) {
                        if (D2==0){
                            D2=1;
                        }
                        //获得地堆放货地点属性
                        String end=km.getPropertyByOrder(v2OrderName,"end");
                        String UUID=km.getPropertyByOrder(v2OrderName,"UUID");
                        String Lpnnumber=km.getPropertyByOrder(v2OrderName,"Lpnnumber");
                            if(A2==0&&km.getDriveOrderOperation(v2OrderName).startsWith("Unload")&&
                                    km.getDriveOrderState(v2OrderName).equals("TRAVELLING")&&
                                    //并且当前点位不等于放货进叉点位
                                    !km.getPosition("Vehicle-0002").equals(km.getDriverOrderPoint(v2OrderName))
                                    ){
                                getFinish_request=new GetFinish_Request();
                                getFinish_request.setuUID(UUID);
                                getFinish_request.setRequestAPI("Ord_GetFinish");
                                list=new ArrayList<Data>();
                                data=new Data();
                                data.setOrderId(v2OrderName);
                                data.setRgnNO("02");
                                list.add(data);
                                getFinish_request.setList(list);
                                String jsonOutput= JSON.toJSONString(getFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_GetFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("二车取货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }

                                A2=1;
                            }
                            String v2orderStatus = km.getOrderStatus(v2OrderName);
                            if(B2==0&&v2orderStatus.equals("FINISHED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(1);
                                dataMove.setLpnnumber(Lpnnumber);
                                dataMove.setOrderId(v2OrderName);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("二车放货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                B2=1;
                                D2=0;
                            }
                            if(C2==0&&v2orderStatus.equals("FAILED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(2);
                                dataMove.setOrderId(v2OrderName);
                                dataMove.setLpnnumber(Lpnnumber);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("二车任务失败");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                C2=1;
                                D2=0;
                            }
                    }
                }

                if(!v3OrderName.equals("N/A")) {
                    if(!v3OrderName.startsWith("Park") && !v3OrderName.startsWith("Recharge")
                            && !v3OrderName.startsWith("TOrder") && !v3OrderName.startsWith("Move")) {
                        if (D3==0){
                            D3=1;
                        }
                        //获得地堆放货地点属性
                        String end=km.getPropertyByOrder(v3OrderName,"end");
                        String UUID=km.getPropertyByOrder(v3OrderName,"UUID");
                        String Lpnnumber=km.getPropertyByOrder(v3OrderName,"Lpnnumber");
                        /*只有在任务快要结束的时候才能进入次循环*/
                        /*怎么知道任务快要结束了*/
                            if(A3==0&&km.getDriveOrderOperation(v3OrderName).startsWith("Unload")&&
                                    km.getDriveOrderState(v3OrderName).equals("TRAVELLING")&&
                                    //并且当前点位不等于放货进叉点位
                                    !km.getPosition("Vehicle-0003").equals(km.getDriverOrderPoint(v3OrderName))
                                    ){
                                getFinish_request=new GetFinish_Request();
                                getFinish_request.setuUID(UUID);
                                getFinish_request.setRequestAPI("Ord_GetFinish");
                                list=new ArrayList<Data>();
                                data=new Data();
                                data.setOrderId(v3OrderName);
                                data.setRgnNO("03");
                                list.add(data);
                                getFinish_request.setList(list);
                                String jsonOutput= JSON.toJSONString(getFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_GetFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("三车取货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }

                                A3=1;
                            }
                            String v3orderStatus = km.getOrderStatus(v3OrderName);
                            if(B3==0&&v3orderStatus.equals("FINISHED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(1);
                                dataMove.setLpnnumber(Lpnnumber);
                                dataMove.setOrderId(v3OrderName);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("三车放货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                B3=1;
                                D3=0;
                            }
                            if(C3==0&&v3orderStatus.equals("FAILED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(2);
                                dataMove.setOrderId(v3OrderName);
                                dataMove.setLpnnumber(Lpnnumber);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("三车任务失败");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                C3=1;
                                D3=0;
                            }
                    }
                }

                if(!v4OrderName.equals("N/A")) {
                    if(!v4OrderName.startsWith("Park") && !v4OrderName.startsWith("Recharge")
                            && !v4OrderName.startsWith("TOrder") && !v4OrderName.startsWith("Move")) {
                        if (D4==0){
                            D4=1;
                        }
                        //获得地堆放货地点属性
                        String end=km.getPropertyByOrder(v4OrderName,"end");
                        String UUID=km.getPropertyByOrder(v4OrderName,"UUID");
                        String Lpnnumber=km.getPropertyByOrder(v4OrderName,"Lpnnumber");
                        /*只有在任务快要结束的时候才能进入次循环*/
                            if(A4==0&&km.getDriveOrderOperation(v4OrderName).startsWith("Unload")&&
                                    km.getDriveOrderState(v4OrderName).equals("TRAVELLING")&&
                                    //并且当前点位不等于放货进叉点位
                                    !km.getPosition("Vehicle-0004").equals(km.getDriverOrderPoint(v4OrderName))
                                    ){
                                getFinish_request=new GetFinish_Request();
                                getFinish_request.setuUID(UUID);
                                getFinish_request.setRequestAPI("Ord_GetFinish");
                                list=new ArrayList<Data>();
                                data=new Data();
                                data.setOrderId(v4OrderName);
                                data.setRgnNO("04");
                                list.add(data);
                                getFinish_request.setList(list);
                                String jsonOutput= JSON.toJSONString(getFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_GetFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("四车取货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                A4=1;
                            }
                            String v4orderStatus = km.getOrderStatus(v4OrderName);
                            if(B4==0&&v4orderStatus.equals("FINISHED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(1);
                                dataMove.setLpnnumber(Lpnnumber);
                                dataMove.setOrderId(v4OrderName);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("四车放货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                B4=1;
                                D4=0;
                            }
                            if(C4==0&&v4orderStatus.equals("FAILED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(2);
                                dataMove.setOrderId(v4OrderName);
                                dataMove.setLpnnumber(Lpnnumber);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("四车任务失败");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                C4=1;
                                D4=0;
                            }
                    }
                }

                if(!v5OrderName.equals("N/A")) {
                    if(!v5OrderName.startsWith("Park") && !v5OrderName.startsWith("Recharge")
                            && !v5OrderName.startsWith("TOrder") && !v5OrderName.startsWith("Move")) {
                        if (D5==0){
                            D5=1;
                        }
                        //获得地堆放货地点属性
                        String end=km.getPropertyByOrder(v5OrderName,"end");
                        String UUID=km.getPropertyByOrder(v5OrderName,"UUID");
                        String Lpnnumber=km.getPropertyByOrder(v5OrderName,"Lpnnumber");
                        /*只有在任务快要结束的时候才能进入次循环*/
                            if(A5==0&&km.getDriveOrderOperation(v5OrderName).startsWith("Unload")&&
                                    km.getDriveOrderState(v5OrderName).equals("TRAVELLING")&&
                                    //并且当前点位不等于放货进叉点位
                                    !km.getPosition("Vehicle-0005").equals(km.getDriverOrderPoint(v5OrderName))
                                    ){
                                getFinish_request=new GetFinish_Request();
                                getFinish_request.setuUID(UUID);
                                getFinish_request.setRequestAPI("Ord_GetFinish");
                                list=new ArrayList<Data>();
                                data=new Data();
                                data.setOrderId(v5OrderName);
                                data.setRgnNO("05");
                                list.add(data);
                                getFinish_request.setList(list);
                                String jsonOutput= JSON.toJSONString(getFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_GetFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("五车取货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                A5=1;
                            }
                            String v5orderStatus = km.getOrderStatus(v5OrderName);
                            if(B5==0&&v5orderStatus.equals("FINISHED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(1);
                                dataMove.setLpnnumber(Lpnnumber);
                                dataMove.setOrderId(v5OrderName);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("五车放货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                B5=1;
                                D5=0;
                            }
                            if(C5==0&&v5orderStatus.equals("FAILED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(2);
                                dataMove.setOrderId(v5OrderName);
                                dataMove.setLpnnumber(Lpnnumber);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("五车任务失败");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                C5=1;
                                D5=0;
                            }
                    }
                }

                if(!v6OrderName.equals("N/A")) {
                    if(!v6OrderName.startsWith("Park") && !v6OrderName.startsWith("Recharge")
                            && !v6OrderName.startsWith("TOrder") && !v6OrderName.startsWith("Move")) {
                        if (D6==0){
                            D6=1;
                        }
                        //获得地堆放货地点属性
                        String end=km.getPropertyByOrder(v6OrderName,"end");
                        String UUID=km.getPropertyByOrder(v6OrderName,"UUID");
                        String Lpnnumber=km.getPropertyByOrder(v6OrderName,"Lpnnumber");
                            if(A6==0&&km.getDriveOrderOperation(v6OrderName).startsWith("Unload")&&
                                    km.getDriveOrderState(v6OrderName).equals("TRAVELLING")&&
                                    //并且当前点位不等于放货进叉点位
                                    !km.getPosition("Vehicle-0006").equals(km.getDriverOrderPoint(v6OrderName))
                                    ){
                                getFinish_request=new GetFinish_Request();
                                getFinish_request.setuUID(UUID);
                                getFinish_request.setRequestAPI("Ord_GetFinish");
                                list=new ArrayList<Data>();
                                data=new Data();
                                data.setOrderId(v6OrderName);
                                data.setRgnNO("06");
                                list.add(data);
                                getFinish_request.setList(list);
                                String jsonOutput= JSON.toJSONString(getFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_GetFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("六车取货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }

                                A6=1;
                            }
                            String v6orderStatus = km.getOrderStatus(v6OrderName);
                            if(B6==0&&v6orderStatus.equals("FINISHED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(1);
                                dataMove.setLpnnumber(Lpnnumber);
                                dataMove.setOrderId(v6OrderName);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("六车放货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                B6=1;
                                D6=0;
                            }
                            if(C6==0&&v6orderStatus.equals("FAILED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(2);
                                dataMove.setOrderId(v6OrderName);
                                dataMove.setLpnnumber(Lpnnumber);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("六车任务失败");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                C6=1;
                                D6=0;
                            }
                    }
                }

                if(!v7OrderName.equals("N/A")) {
                    if(!v7OrderName.startsWith("Park") && !v7OrderName.startsWith("Recharge")
                            && !v7OrderName.startsWith("TOrder") && !v7OrderName.startsWith("Move")) {
                        if (D7==0){
                            D7=1;
                        }
                        //获得地堆放货地点属性
                        String end=km.getPropertyByOrder(v7OrderName,"end");
                        String UUID=km.getPropertyByOrder(v7OrderName,"UUID");
                        String Lpnnumber=km.getPropertyByOrder(v7OrderName,"Lpnnumber");

                            if(A7==0&&km.getDriveOrderOperation(v7OrderName).startsWith("Unload")&&
                                    km.getDriveOrderState(v7OrderName).equals("TRAVELLING")&&
                                    //并且当前点位不等于放货进叉点位
                                    !km.getPosition("Vehicle-0007").equals(km.getDriverOrderPoint(v7OrderName))
                                    ){
                                getFinish_request=new GetFinish_Request();
                                getFinish_request.setuUID(UUID);
                                getFinish_request.setRequestAPI("Ord_GetFinish");
                                list=new ArrayList<Data>();
                                data=new Data();
                                data.setOrderId(v7OrderName);
                                data.setRgnNO("07");
                                list.add(data);
                                getFinish_request.setList(list);
                                String jsonOutput= JSON.toJSONString(getFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_GetFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("七车取货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                A7=1;
                            }
                            String v7orderStatus = km.getOrderStatus(v7OrderName);
                            if(B7==0&&v7orderStatus.equals("FINISHED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(1);
                                dataMove.setLpnnumber(Lpnnumber);
                                dataMove.setOrderId(v7OrderName);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("七车放货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                B7=1;
                                D7=0;
                            }
                            if(C7==0&&v7orderStatus.equals("FAILED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(2);
                                dataMove.setOrderId(v7OrderName);
                                dataMove.setLpnnumber(Lpnnumber);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("七车任务失败");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                C7=1;
                                D7=0;
                            }
                    }
                }

                if(!v8OrderName.equals("N/A")) {
                    if(!v8OrderName.startsWith("Park") && !v8OrderName.startsWith("Recharge")
                            && !v8OrderName.startsWith("TOrder") && !v8OrderName.startsWith("Move")) {
                        if (D8==0){
                            D8=1;
                        }
                        //获得地堆放货地点属性
                        String end=km.getPropertyByOrder(v8OrderName,"end");
                        String UUID=km.getPropertyByOrder(v8OrderName,"UUID");
                        String Lpnnumber=km.getPropertyByOrder(v8OrderName,"Lpnnumber");
                        /*只有在任务快要结束的时候才能进入次循环*/
                        /*怎么知道任务快要结束了*/
                            if(A8==0&&km.getDriveOrderOperation(v8OrderName).startsWith("Unload")&&
                                    km.getDriveOrderState(v8OrderName).equals("TRAVELLING")&&
                                    //并且当前点位不等于放货进叉点位
                                    !km.getPosition("Vehicle-0008").equals(km.getDriverOrderPoint(v8OrderName))
                                    ){
                                getFinish_request=new GetFinish_Request();
                                getFinish_request.setuUID(UUID);
                                getFinish_request.setRequestAPI("Ord_GetFinish");
                                list=new ArrayList<Data>();
                                data=new Data();
                                data.setOrderId(v8OrderName);
                                data.setRgnNO("08");
                                list.add(data);
                                getFinish_request.setList(list);
                                String jsonOutput= JSON.toJSONString(getFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_GetFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("八车取货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }

                                A8=1;
                            }
                            String v8orderStatus = km.getOrderStatus(v8OrderName);
                            if(B8==0&&v8orderStatus.equals("FINISHED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(1);
                                dataMove.setLpnnumber(Lpnnumber);
                                dataMove.setOrderId(v8OrderName);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("八车放货完成");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                B8=1;
                                D8=0;
                            }
                            if(C8==0&&v8orderStatus.equals("FAILED")) {
                                moveFinish_request=new MoveFinish_Request();
                                moveFinish_request.setuUID(UUID);
                                moveFinish_request.setRequestAPI("Order_MoveFinish");
                                dataMove=new DataMove();
                                dataMove.setFinishType(2);
                                dataMove.setOrderId(v8OrderName);
                                dataMove.setLpnnumber(Lpnnumber);
                                moveFinish_request.setData(dataMove);
                                String jsonOutput= JSON.toJSONString(moveFinish_request);
                                try {
                                    String jsonReturn=HttpClientTools.sendPostDataByJson("http://localhost:9998/AGV/Ord_MoveFinish",jsonOutput,"utf-8");
                                    Response response=JSON.parseObject(jsonReturn, Response.class);
                                    System.out.println("八车任务失败");
                                    System.out.println("反馈的内容是"+response.getCode());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                C8=1;
                                D8=0;
                            }
                    }
                }
            }

        }

    }
    @PostConstruct
    public void firstStart(){
        /*开启线程用来更新车辆的状态，只更新车辆放货完成的状态*/
        /*只开启一个线程来更新所有车的状态*/
        new Thread(new changeState()).start();
    }
}
